/*
 * @Author: xiaosihan 
 * @Date: 2021-12-21 18:32:37 
 * @Last Modified by: xiaosihan
 * @Last Modified time: 2022-02-11 18:22:10
 */

import ApngTexture from "three-base/ApngTexture";
import { Float32BufferAttribute, Points, PointsMaterial, WebGLRenderer } from "three";
import lightPoinsMapPNG from "./lightPoinsMap.png";

/**
 * 光点
 */
export default class LightPoint extends Points {

    constructor() {
        super();
        this.init();
    }

    static frame = 0;

    static isInit = false;

    static apngTexture = new ApngTexture(lightPoinsMapPNG);

    static material = new PointsMaterial({
        map: LightPoint.apngTexture,
        transparent: true,
        size: 500,
        depthTest: false
    });

    renderOrder = 10;

    init() {
        this.material = LightPoint.material;
        this.geometry.setAttribute("position", new Float32BufferAttribute([0, 0, 0], 3));
    }

    onBeforeRender = (renderer: WebGLRenderer) => {

        const frame = renderer.info.render.frame;

        if (LightPoint.frame !== frame) {
            LightPoint.frame = frame;
            LightPoint.apngTexture.needsUpdate = true;
        }

    }

}